package dto.resDto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
public class RespData {
    
    private boolean success;
    /**
     * 200：请求成功 201：创建、修改成功 204：删除成功 400：参数错误 401：未登录 403：禁止访问 404：未找到 500：系统错误
     */
    private Integer code;

    private String msg;

    private Long count;

    private Object data;

    public RespData(boolean success) {
        this.success = success;
    }

    public RespData() { }

    public static RespData success(String msg, Object object) {
        RespData RespData = new RespData(true);
        RespData.code = 0;
        RespData.data = object;
        RespData.msg = msg;
        return  RespData;
    }

    public static RespData success(Object object, Long count) {
        RespData RespData = new RespData(true);
        RespData.code = 0;
        RespData.data = object;
        RespData.count = count;
        return  RespData;
    }

    public static RespData success() {
        return new RespData(true);
    }

    public static RespData fail(String msg) {
        RespData RespData = new RespData(false);
        RespData.msg = msg;
        return RespData;
    }

    public static RespData fail() {
        RespData RespData = new RespData(false);
        //RespData.setCode(0);
        return RespData;
    }

    public static RespData fail(String msg, Object data) {
        RespData RespData = new RespData(false);
      //  RespData.setMsg(msg);
       // RespData.setData(data);
        return RespData;
    }

    public RespData(Integer code, Long count, Object data) {
        this.code = code;
        this.count = count;
        this.data = data;
    }

    public RespData(boolean success, Integer code, Object data) {
        this.success = success;
        this.code = code;
        this.data = data;
    }

    public RespData(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    public RespData(boolean success, String msg, Object data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    public RespData(boolean success, Integer code, String msg, Long count, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }

    public Map<String, Object> toMap() {
        HashMap<String, Object> result = new HashMap<String, Object>();
        result.put("code", code);
        result.put("msg", msg);
        result.put("count", count);
        result.put("data", data);
        return result;
    }
}
